import os
from collections import deque

from loguru import logger
from PyQt5.QtCore import QJsonDocument, QByteArray


def load_from_file(file_name):
    path = os.path.join(file_name)
    cmds = deque([])
    with open(file=path, mode='r', encoding='utf-8') as file:
        json_array_str = file.read()
        json_obj = QJsonDocument.fromJson(QByteArray(str(json_array_str).encode("utf-8"))).object()
        array_obj = json_obj["array"]
        array = array_obj.toArray()

        for j in array:
            cmds.append(j.toObject()["cmd"].toString())

        return cmds